﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Delonix_Regia_Hotel_Management_System.Class;

namespace Delonix_Regia_Hotel_Management_System
{
    public partial class All_Guest_In_All_Rooms_Report : Form
    {
        public All_Guest_In_All_Rooms_Report()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 F = new Form1();
            this.Hide();
            F.Show(); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (LogInClass.position == "Administrator")
            {
                Main__Management_and_Administrator_ mainA = new Main__Management_and_Administrator_();
                this.Hide();
                mainA.Show();
            }
            else
            {
                Main__Receptionist_ mainR = new Main__Receptionist_();
                this.Hide();
                mainR.Show();
            }


        }

        private void All_Guest_In_All_Rooms_Report_Load(object sender, EventArgs e)
        {

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            List<Room> room = new List<Room>();

            string searchDate = Convert.ToString(dateTimePicker1.Value.Date.Year + "/" + dateTimePicker1.Value.Date.Month + "/" + dateTimePicker1.Value.Date.Day);

            room = DBManager.getRoomByDate(searchDate);
            

            BindingSource binding = new BindingSource();
            binding.DataSource = room;
            dataGridView1.DataSource = binding;

            dataGridView1.Columns["roomStatus"].Visible = false;
            dataGridView1.Columns["roomStartingDate"].Visible = false;
            dataGridView1.Columns["roomEndingDate"].Visible = false;
            dataGridView1.Columns["roomType"].Visible = false;
        }

        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
            ExcelApp.Application.Workbooks.Add(Type.Missing);
            ExcelApp.Columns.ColumnWidth = 10;

            ExcelApp.Cells[1, 1] = dataGridView1.Columns[0].HeaderText;
            ExcelApp.Cells[1, 2] = dataGridView1.Columns[2].HeaderText;
            ExcelApp.Cells[1, 3] = dataGridView1.Columns[3].HeaderText;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                ExcelApp.Cells[i + 2, 1] = dataGridView1.Rows[i].Cells[0].Value.ToString();
                ExcelApp.Cells[i + 2, 2] = dataGridView1.Rows[i].Cells[2].Value.ToString();
                ExcelApp.Cells[i + 2, 3] = dataGridView1.Rows[i].Cells[3].Value.ToString();
            }

            string datetime = DateTime.Now.ToString("MMddyyyyhmmtt");
            ExcelApp.ActiveWorkbook.SaveCopyAs("F:\\AllGuestInAllRoomReport" + datetime + ".xls");
            ExcelApp.ActiveWorkbook.Saved = true;
            ExcelApp.Quit();
            MessageBox.Show("Excel file created,you can find the file F:\\AllGuestInAllRoomReport.xls");
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            PrintDGV.Print_DataGridView(dataGridView1);
        }

        
      
       
    
    }
}
